<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>待分配</title>
    <c:import url="../../header.jsp"/>
</head>
<body>
<div class="content-warp">
    <p id="timeout" name="timeout" hidden data-timeout="${TIME_OUT}"></p>
    <div class="dgg-list-top-warp">

        <div class="screen-search">
            <ul>
                <li>
                    <label>客户姓名：</label>
                    <input type="text" class="dggui-input dggui-input-normal" id="customerName" name="customerName" placeholder="输入客户姓名" maxlength="50">
                </li>
                <li>
                    <label>签单时间：</label>
                    <input type="text" readonly class="dggui-input dggui-time-range" id="signTime" name="signTime">
                    <i class="iconfont icon-rili"></i>
                </li>

                <li>
                    <label>所属生产事业部：</label>
                    <select id="productOrgId" id="productOrgId" name="productOrgId" class="dggui-select">
                    </select>
                </li>
                <li>
                    <label>业务类型：</label>
                    <div name="typeCode" id="typeCode" name="typeCode"></div>
                </li>
                <li>
                    <label>产品：</label>
                    <select name="productCode" id="productCode" class="dggui-select">
                    </select>
                </li>
                <li>
                    <label>渠道：</label>
                    <select name="channelCode" id="channelCode" class="dggui-select">
                        <option value=''>请选择</option>
                    </select>
                </li>
                <li>
                    <label>签单商务：</label>
                    <select id="signUserId" name="signUserId" class="dggui-select">
                    </select>
                </li>
                <li>
                    <label>签单部门：</label>
                    <div class="tree-select-warp">
                        <input type="text" class="dggui-input input-selct-tree" id="signOrg" name="signOrg"  data-id="" value=""  style="width: 320px"  />
                    </div>
                </li>
                <li>
                    <label>关键字：</label>
                    <input type="text" class="dggui-input dggui-input-large" id="searchKey" name="searchKey" placeholder="订单编号/生产单编号/客户号码" maxlength="50" style="width: 190px;">
                </li>
               <%-- <li>
                    <label>需求金额：</label>
                    <input type="number" class="dggui-input dggui-input-large" id="moneyMin" name="moneyMin" placeholder="输入最小金额" min="0" max="99999999999">~
                    <input type="number" class="dggui-input dggui-input-large" id="moneyMax" name="moneyMax" placeholder="输入最大金额" min="0" max="99999999999">
                </li>--%>
                <li>
                    <button class="dggui-btn searchBtn" onclick="return false;">搜索</button>
                    <button class="dggui-btn dggui-btn-primary" onclick="cleanSearch();return false;">清空条件</button>
                    <d:hasUrlAuth authCode="RZSC_OPERATION_EXPORT">
                    <button class="dggui-btn dggui-btn-green" onclick="excelExportAllot('${basePath}/rzsc/allocate/excel_export_wait_allot.do') ;return false;">导出</button>
                    </d:hasUrlAuth>
                </li>
            </ul>
        </div>
    </div>
    <div class="list-content">
        <div class="tool-bar">
            <div class="fl">

                <d:hasUrlAuth authCode="RZSC_OPERATION_CALL">
                <a href="javascript:void(0)"class="dggui-btn" onclick="callPhoneByProduction($('#waitAllocationTable'))">打电话</a>
                </d:hasUrlAuth>
                <d:hasUrlAuth authCode="RZSC_OPERATION_ALLOT">
                <a href="javascript:void(0)"class="dggui-btn" onclick="allocate($('#waitAllocationTable'))">分配</a>
                </d:hasUrlAuth>
            </div>
            <div class="fr node-state" >
                <ul>
                    <li class="not-finish">分配超期</li>
                </ul>
            </div>
        </div>
        <div class="table-warp">
            <table class="dggui-table" id="waitAllocationTable">
            </table>
        </div>
    </div>
</div>

<c:import url="../../footer.jsp"/>
<script>
    var tables;
    var timeout = '${TIME_OUT}';
    var waitAllocation = {
        "list": sysInfo.basePath + "/rzsc/allocate/list.do",//分页数据
        "allocatePage": sysInfo.basePath + "/rzsc/allocate/allot_scorder_page.html"//分配弹窗
    }
    dggui.use(['table', 'select2', 'distpicker', 'dggdate','droptree'], function () {
        var table = dggui.table;
        var select2 = dggui.select2;
        var distpicker = dggui.distpicker;
        var dggdate = dggui.dggdate;
        var droptree=dggui.droptree;
        //初始化所属生产事业部
        syb("#productOrgId");
        select2.render({
            placeholder: "请选择",
            elem: $('#productOrgId'),
            allowClear: true,
            width: "160px"
        });

        select2.render({
            placeholder: "请选择",
            allowClear: true,
            elem: $('#productCode'),
            width: "160px"
        });
        //初始化业务类型及产品
        distpicker.render({
            url: "${basePath}/rzsc/common/tree_book_list.do?code=BUS_YT_DK&type=2&level=2", // 请求地址
            elem: '#typeCode', // 容器Id
            type: 2,
            placeholder: '选择业态',
            defaultParentCode:'BUS_YT_DK',
            callback:function () {//如果不需要选产品就把callback整个方法注释掉
                var code = $("#typeCode .plug-in-code").val();
                initProductCode("#productCode",code);
                select2.render({
                    placeholder: "请选择",
                    allowClear: true,
                    elem: $('#productCode'),
                    width: "160px"
                });
                var produtId = $("#productCode").val();
                initChannel("#channelCode",produtId);
                select2.render({
                    placeholder: "请选择",
                    allowClear: true,
                    elem: $('#channelCode'),
                    width: "160px"
                });
            },
            callbackClear:function () {
                $("#productCode").find("option").remove();
                $("#productCode").append("<option value=''>请选择</option>");
                $("#channelCode").find("option").remove();
                $("#channelCode").append("<option value=''>请选择</option>");
            }
        });

        // 加载部门下拉框
        queryAllDep("#signOrg");
        //产品初始化
        $('#typeCode').on('change', function (e) {
            var code = $("#typeCode .plug-in-code").val();
            initProductCode("#productCode",code);
            select2.render({
                placeholder: "请选择",
                allowClear: true,
                elem: $('#productCode'),
                width: "160px"
             });
        });

        //渠道初始化
        $('#productCode').on('change', function (e) {
            var produtId = $("#productCode").val();
            initChannel("#channelCode",produtId);
            select2.render({
                placeholder: "请选择",
                allowClear: true,
                elem: $('#channelCode'),
                width: "160px"
            });
        });

        //初始化签单商务
        initUser("bus_advisor", "role", "#signUserId");
        select2.render({
            placeholder: "请选择",
            allowClear: true,
            elem: $('#signUserId'),
            width: "160px"
        });
        //初始化签单时间
        dggdate.render({
            elem: '#signTime',
            type: 'date',
            range: '~'
        });

        var opt = {
            "elem": "#waitAllocationTable",
            "ajax": waitAllocation.list,
            "scrollX": "true",//是否开启横项滚动
            "fixedColumns": {//锁定列，只有开启scrollX时才生效
                "leftColumns": 4,//左侧锁定2列
                "rightColumns": 1//右侧锁定1列
            },
            "fnServerParams": function (aoData) {
                // var moneyMax = $("#moneyMax").val().trim();
                // var moneyMin = $("#moneyMin").val().trim();
                //搜索条件
                aoData = $.extend(aoData, {
                        // customerPhone: $("#customerPhone").val(),
                        productOrgId: $("#productOrgId").val(),
                        typeCode: $("#typeCode").find(".plug-in-code").val(),
                        productId: $("#productCode").val(),
                        signUserId:$("#signUserId").val(),
                        channelId:$("#channelCode").val(),
                        orderTime: $("#signTime").val(),
                        searchKey: $("#searchKey").val(),
                        signOrgOrBusId:$("#signOrg").attr("data-id"),
                        customerName:$("#customerName").val(),
                        // moneyMax:moneyMax,
                        // moneyMin:moneyMin,
                    }
                )
                return aoData;
            },
            "aoColumns": [{
                "sClass": "check-th",
                "title": "<input type='checkbox'  class='checkall'>",
                "orderable": false,
                "render": function (data, type, full, meta) {
                    return '<input type="checkbox" class="checkchild" name="checkchild" value="' + data + '">';
                }
            }, {
                'title': '序号',
                "orderable": false,
                "render": function (data, type, full, meta) {
                    return meta.row + 1;
                }
            },
                {
                    'title': '所属生产事业部',
                    'data': "productOrgName",
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        var htm = '<div class="order-render"><b>' + data ? data : '' + '<b></div>';
                        return htm;
                    }
                },
                {
                    "title": "订单编号",
                    "orderable": false,
                    "data": "orderNo",
                    "render": function (data, type, full, meta) {
                        return ('<a href="javascript:;" class="dggui-link"  onclick="openBusinessDetail(\'' + full.orderNo + '\',\'' + full.orderId + '\')" /><span>' + data + '</span></a>');
                        /*return data;*/
                    }
                },
                {
                    'title': '生产订单编号',
                    'data': "scProductOrderNo",
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        var htm = '<a href="javascript:void(0)" class="dggui-link" onclick="openOrderInfoDetail(\''+data+'\',\''+row.id+'\')">'+data+'</a>';
                        return htm;
                    }
                }, {
                    'title': '客户',
                    'data': "customerName",
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        var htm = '<div class="order-render">' +
                            '<p><span>' + emptyStringConvert(row.customerName) + '</span></p>' +
                            '<p>' + emptyStringConvert(row.customerPhone) + '</p>' +
                            '</div>'
                        return htm;
                    }
                },
                {
                    "title":"合同编号",
                    "orderable": false,
                    "data": "contractNo",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '业务类型',
                    'data': "businessProductName",
                    "orderable": false,
                    "render": function(data, type, row, meta) {
                        var htm = '<div class="order-render">' +
                        '<p class="line1" title="'+data ? data : ''+'"><span >' +data ? data : '' + '</span></p>'+
                            '</div>'
                        return htm;
                    }
                },
                {
                    'title': '产品',
                    'data': "productName",
                    "orderable": false,
                    "render": function(data, type, row, meta) {
                        var htm = '<div class="order-render">' +
                        '<p class="line1" title="'+data+'"><span >' +data ? data : '' + '</span></p>'+
                            '</div>'
                        return htm;
                    }
                },
                {
                    'title': '商品属性',
                    'data': "goodsName",
                    "orderable": false,
                    "render": function(data, type, row, meta) {
                        var htm = '<div class="order-render">' +
                        '<p class="line1" title="'+data+'"><span >' +data ? data : '' + '</span></p>'+
                            '</div>'
                        return htm;
                    }
                },
                {
                    'title': '渠道',
                    'data': "channelName",
                    "orderable": false,
                    "render": function(data, type, row, meta) {
                        var htm = '<div class="order-render">' +
                        '<p class="line1" title="'+data+'"><span >' +data ? data : '' + '</span></p>'+
                            '</div>'
                        return htm;
                    }
                },
                {
                    'title': '签单时间',
                    'data': "orderTime",
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        var htm = '<div class="order-render"><p>' + data ? data : '' + '</p></div>';
                        return htm;
                    }
                },
                {
                    'title': '签单商务',
                    'data': "signUserName",
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        return emptyStringConvert(row.signUserName) + '<p>' + emptyStringConvert(row.signUserOrgName) + '</p>';
                    }
                },
               /* {
                    'title': '签单部门',
                    'data': "signUserOrgName",
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        var htm = '<div class="order-render">' +
                        '<p class="line1" title="' + data + '"><span >' + data ? data : '' + '</span></p>' +
                            '</div>'
                        return htm;
                    }
                },*/
                {
                    'title': '需求金额（元）',
                    'data': "loanAmount",
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        var htm = '<div class="order-render">' +
                        '<p><span >' + data ? data : '' + '</span></p>' +
                            '</div>'
                        return htm;
                    }
                },
                {
                    'title': '最新备注',
                    'data': "lastRemark",
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        return '<div class="line1" title="'+data+'"><p>' + strInterception(data,10) + '</p></div>' + '<p>'+emptyStringConvert(row.lastRemarkTime)+'</p>';
                    }
                },
                {
                    'title': '操作',
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        var htm = '<a href="javascript:void(0)" class="dggui-link" onclick="remarkOrder(\''+row.id+'\',$(\'#waitAllocationTable\'));">备注</a>';
                        return htm;
                    }
                }
            ],
            "columnDefs": [{
                targets: [3], //第1，2，3列
                createdCell: function (td, cellData, rowData, row, col) {
                 if (rowData.distributionTimeOutStatus == timeout && rowData.status == '待分配') {//分配超期
                        $(td).parent().addClass("gray");//分配
                        return;
                    }
                }
            }]
        };
        tables = table.render(opt);
        $('.searchBtn').click(function () {
        /*    var moneyMax = $("#moneyMax").val().trim();
            var moneyMin = $("#moneyMin").val().trim();
            if(!checkMoneySearch(moneyMin,moneyMax)){
                return false;
            }*/
            tables.ajax.reload();
        });

        // 处理dataTable 异常错误信息
        $.fn.dataTable.ext.errMode = 'none';//不抛出异常
        tables.on( 'error.dt', function ( e, settings, techNote, message ) {
            //dggui.dialog.errors("表格查询错误，请联系管理员", 2000);
           if(checkEmpty(settings.jqXHR.responseJSON.error)){dggui.dialog.errors(settings.jqXHR.responseJSON.error, 2000);}
        });
    });

    function excelExportAllot(url) {
        /*var moneyMax = $("#moneyMax").val().trim();
        var moneyMin = $("#moneyMin").val().trim();
        if(!checkMoneySearch(moneyMin,moneyMax)){
            return;
        }*/
        var obj = new Object();
        obj.customerPhone= $("#customerPhone").val();
        obj.productOrgId= $("#productOrgId").val();
        obj.typeCode= $("#typeCode").find(".plug-in-code").val();
        obj.productId= $("#productCode").val();
        obj.signUserId=$("#signUserId").val();
        obj.channelId=$("#channelCode").val();
        obj.orderTime=$("#signTime").val();
        obj.searchKey=$("#searchKey").val();
        obj.signOrgOrBusId=$("#signOrg").attr("data-id");
        obj.customerName=$("#customerName").val();
       /* obj.moneyMax=moneyMax;
        obj.moneyMin=moneyMin;*/
        formSubmit(url, obj);
    }

</script>
</body>
</html>